package edu.byu.intex2.data.bo;

import edu.byu.intex2.data.DataException;
import edu.byu.intex2.data.dao.*;

/**
 * @author Jason Whiting
 */
public class SaleLine extends BusinessObject
{
    // Prices

    private double actualPrice;
    private double listPrice;

    // Sale
    private String saleId;
    private Sale sale;

    // Physical Car
    private String physicalCarId;
    private PhysicalCar physicalCar;

    /**
     * Creates a new instance of BusinessObject
     * @param id
     */
    public SaleLine(String id)
    {
        super(id);
    }//constructor

    //Quick Access Method
    public void save() throws DataException
    {
        try
        {
            SaleLineDAO.getInstance().save(this);
        } catch (DataException e)
        {
            e.printStackTrace();
        }
    }

    /** @return the actualPrice     */
    public double getActualPrice()
    {
        return actualPrice;
    }

    /** @param actualPrice the actualPrice to set     */
    public void setActualPrice(double actualPrice)
    {
        this.actualPrice = actualPrice;
        setDirty();
    }

    /** @return the listPrice     */
    public double getListPrice()
    {
        return listPrice;
    }

    /** @param listPrice the listPrice to set     */
    public void setListPrice(double listPrice)
    {
        this.listPrice = listPrice;
        setDirty();
    }

    /** @return the saleId     */
    public String getSaleId()
    {
        return saleId;
    }

    /** @param saleId the saleId to set     */
    public void setSaleId(String saleId)
    {
        this.saleId = saleId;
        setDirty();
    }

    /** @return the sale     */
    public Sale getSale() throws Exception
    {
        if (sale == null)
        {
            sale = SaleDAO.getInstance().read(saleId);
        }
        return sale;
    }

    /** @param sale the sale to set     */
    public void setSale(Sale sale)
    {
        this.sale = sale;
        setDirty();
    }

    /** @return the physicalCarId     */
    public String getPhysicalCarId()
    {
        if (physicalCarId == null)
        {
            physicalCarId = physicalCar.getId();
        }
        return physicalCarId;
    }

    /** @param physicalCarId the physicalCarId to set     */
    public void setPhysicalCarId(String physicalCarId)
    {
        this.physicalCarId = physicalCarId;
        setDirty();
    }

    /** @return the physicalCar     */
    public PhysicalCar getPhysicalCar() throws Exception
    {
        if (physicalCar == null)
        {
            physicalCar = PhysicalCarDAO.getInstance().read(physicalCarId);
        }
        return physicalCar;
    }

    /** @param physicalCar the physicalCar to set     */
    public void setPhysicalCar(PhysicalCar physicalCar)
    {
        this.physicalCar = physicalCar;
        setDirty();
    }
}
